package com.newbee.adapter;

import java.util.List;
import java.util.Random;

import javax.xml.transform.Templates;

import org.json.JSONException;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hhu.newbee.R;
import com.newbee.app.SpeechApp;
import com.newbee.http.ServerHttpUtil;
import com.newbee.listbean.QunZuInfoBean;
import com.newbee.textview.AlwaysMarqueeTextView;
import com.readystatesoftware.viewbadger.BadgeView;

public class QunZuAdapter extends BaseAdapter
{

	private static int[] colorSet = new int[] {

	0xff7f8c8d, 0xff16a085, 0xfff39c12, 0xff8e44ad, 0xff27ae60, 0xffd35400

	};

	private Context context;
	private List<QunZuInfoBean> list;

	public QunZuAdapter(Context context, List<QunZuInfoBean> list)
	{
		super();
		this.context = context;
		this.list = list;
	}

	public void setList(List<QunZuInfoBean> list)
	{
		this.list = list;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		if (list != null)
		{
			return list.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int arg0)
	{
		return arg0;
	}

	@Override
	public long getItemId(int arg0)
	{
		return arg0;
	}

	@Override
	public View getView(int p, View v, ViewGroup arg2)
	{

		if (v == null)
		{
			v = LayoutInflater.from(context).inflate(R.layout.listitem_qunzu,
					null);
		}

		ViewHolder holder = new ViewHolder();

		holder.qunzu_name = (TextView) v.findViewById(R.id.qunzu_name);
		holder.qunzu_user = (AlwaysMarqueeTextView) v
				.findViewById(R.id.qunzu_user);
//		holder.numb = (TextView) v.findViewById(R.id.number);
//		holder.numb.setText((p + 1) + "");
//
//		holder.numb.setBackgroundColor(colorSet[p % 6]);
		QunZuInfoBean bean = list.get(p);

		holder.qunzu_name.setText(bean.getQunzuName());

		List<String> temp = bean.getUserList();

		StringBuffer sb = new StringBuffer("");
		for (int i = 0; i < temp.size() - 1; i++)
		{
			//
			try
			{
				sb.append(SpeechApp.getUserNamePair().getString(
						temp.get(i).split("\\$")[0]));
				sb.append(";");
			}
			catch (JSONException e)
			{
				sb.append("");
				e.printStackTrace();
			}
			
		}
		// sb.append(temp.get(temp.size() - 1).split("\\$")[1]);
		try
		{
			sb.append(SpeechApp.getUserNamePair().getString(
					temp.get(temp.size() - 1).split("\\$")[0]));
		}
		catch (JSONException e)
		{
			sb.append("正在加载，请稍等，(づ￣ 3￣)づ");
			e.printStackTrace();
		}
		holder.qunzu_user.setText(sb.toString());
		return v;
	}

	static class ViewHolder
	{

		TextView qunzu_name;

		TextView numb;

		AlwaysMarqueeTextView qunzu_user;

	}

}
